package org.dromara.comm_lhz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.dromara.comm_lhz.entity.AsGridMapTableEntity;
import org.dromara.comm_lhz.entity.vo.GridInfoVO;
import org.dromara.comm_lhz.entity.vo.GridVO;

import java.util.List;

@Mapper
public interface AsGridHMapper extends BaseMapper<AsGridMapTableEntity> {
    @Select("select * from as_grid_map_table ")
    List<GridVO> findTree();

    @Select("select * from as_grid_map_table where  grid_name = #{name}")
    List<GridVO> findTreeByName(String name);

    @Select("SELECT\n" +
        "    ag1.id,\n" +
        "    ag1.grid_name AS name,\n" +
        "    ag1.classify,\n" +
        "    ag2.grid_name AS parentName, -- 显示上级网格名称\n" +
        "    ag1.associated_community,\n" +
        "    ags.NAME AS staffName,\n" +
        "    ags.gridpositions \n" +
        "FROM\n" +
        "    as_grid_map_table ag1\n" +
        "    LEFT JOIN as_grid_staff ags ON ags.grid_id = ag1.id\n" +
        "    LEFT JOIN as_grid_map_table ag2 ON ag2.id = ag1.superior_grid\n" +
        "\t\twhere ag1.id = #{id} ;")
    List<GridInfoVO> selectGridById(Long id);
}
